{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'ilm_short'|trans }} - {{ policy.name }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'ilm'|trans, 'link': {'url': path('ilm')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': policy.name}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/ilm/ilm_read_tabs.html.twig' with {'active': 'summary'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'summary'|trans}) }}

            {% embed 'Embed/buttons_embed.html.twig' %}
                {% import 'Import/app_import.html.twig' as appImport %}
                {% block content %}
                    {% if is_granted('ILM_POLICY_DELETE', policy) %}
                        {{ appImport.buttonModal({
                            'id': 'PolicyDelete',
                            'title': 'delete'|trans,
                            'body': policy.name,
                            'href': path('ilm_delete', {'name': policy.name}),
                        }) }}
                    {% endif %}

                    {% if is_granted('ILM_POLICY_COPY', policy) %}
                        <a class="btn btn-primary btn-sm" href="{{ path('ilm_create', {'policy': policy.name}) }}">{{ 'copy'|trans }}</a>
                    {% endif %}
                {% endblock %}
            {% endembed %}

            <hr>

            <div class="row">
                {{ appImport.dashboardKpi({'title': 'modified_date'|trans, 'badge': {'title': policy.modifiedDate|human_datetime}}) }}

                {{ appImport.dashboardKpi({'title': 'version'|trans, 'badge': {'title': policy.version}}) }}
            </div>
        {% endblock %}
    {% endembed %}


    {% for name, phase in policy.phases %}
        {% embed 'Embed/block_embed.html.twig' %}
            {% import 'Import/app_import.html.twig' as appImport %}
            {% block content %}
                {{ appImport.heading({'level': 3, 'title': name|trans}) }}

                {% if phase['min_age'] is defined %}
                    <p>
                        <strong>{{ 'min_age'|trans }}</strong><br>
                        {{ phase['min_age'] }}
                    </p>

                    {% if phase['actions'] is defined %}
                        {% for name, action_properties in phase['actions'] %}
                            <div class="card bg-{{ theme_color_1 }} border border-secondary card-body{%if false == loop.last %} mb-3{% endif %}">
                                {{ appImport.heading({'level': 4, 'title': name}) }}

                                {% for name, action_property in action_properties %}
                                    {% if action_property is not iterable %}
                                        <p>
                                            <strong>{{ name }}</strong><br>
                                            {{ action_property }}
                                        </p>
                                    {% endif %}
                                {% endfor %}
                            </div>
                        {% endfor %}
                    {% endif %}
                {% endif %}
            {% endblock %}
        {% endembed %}
    {% endfor %}
{% endblock %}
